home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / Counting.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  856 b   |  31 lines

  1. //: C21:Counting.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // The counting algorithms
  7. #include "PrintSequence.h"
  8. #include "Generators.h"
  9. #include <vector>
  10. #include <algorithm>
  11. using namespace std;
  12.  
  13. int main() {
  14.   vector<char> v;
  15.   generate_n(back_inserter(v), 50, CharGen());
  16.   print(v, "v", "");
  17.   // Create a set of the characters in v:
  18.   set<char> cs(v.begin(), v.end());
  19.   set<char>::iterator it = cs.begin();
  20.   while(it != cs.end()) {
  21.     int n = count(v.begin(), v.end(), *it);
  22.     cout << *it << ": " << n << ", ";
  23.     it++;
  24.   }
  25.   int lc = count_if(v.begin(), v.end(), 
  26.     bind2nd(greater<char>(), 'a'));
  27.   cout << "\nLowercase letters: " << lc << endl;
  28.   sort(v.begin(), v.end());
  29.   print(v, "sorted", "");
  30. } ///:~
  31.